<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/penalize/penalizeAdd.css" />
		<link rel="stylesheet" type="text/css" href="css/mui.picker.min.css" />
		<link rel="stylesheet" href="css/mui.poppicker.css" />
	</head>

	<body>
		<form action="" method="post" id="Edit">
			<header class="mui-bar mui-bar-nav">
				<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left">日常监督</a>
				<h1 class="mui-title">新增</h1>
				<a class="mui-icon mui-pull-right save" href="javascript:;" @click="editaddsub()">保存</a>
			</header>
			<div class="mui-content" id="pullrefresh">
				<input type="hidden" name="id" :value="list.id" v-if="pd" />
				<!--<input type="hidden" name="supervise.type" value="1" v-if="!pd"/>-->
				<input type="hidden" id="type" name="supervise.type" :value="type" />
				<input type="hidden" name="supervise.ywid" :value="list.ywid" v-if="pd" />
				
				<input type="hidden" name="supervise.enterid" id="hiddenywid" :value="companydata.ywid||ywid" v-if="!pd" />
				<ul class="mui-table-view" id="compbox">
					<li class="mui-table-view-cell mui-table-view-first ">
						<span class="mui-pull-left">被查单位信息</span>
					</li>
					<li class="mui-table-view-cell  mui-table-view-list mui-clearfix" xbzx-verify="name">
						<div class="mui-input-row border" id="companyinput-box" v-if="!flag">
							<label class="must">被查单位：</label>
							<!--编辑-->
							<input id="companyinput" type="text" class="mui-input-clear" v-on:input="companysearch()" placeholder="请输入被查单位" readonly="" v-if="pd">
							<!--新增-->
							<input id="companyinput" title="被查单位" type="text" class="mui-input-clear" v-on:input="companysearch()" placeholder="请输入被查单位" v-else>
							<!--xzqh新增显示-->
							<input type="hidden" name="supervise.xzqh" id="xzqh" value="" v-if="!pd" />
						</div>
						<div class="mui-input-row border" id="companyinput-box" v-else>
							<label class="must">被查单位：</label>
							<!--扫一扫新增-->
							<input id="companyinput" type="text" class="mui-input-clear" v-on:input="companysearch()" readonly="" placeholder="请输入被查单位" :value="addlist.name">
							<!--xzqh扫一扫显示-->
							<input type="hidden" name="supervise.xzqh" id="xzqh" :value="addlist.city" />
						</div>
					</li>
					<ul id="companylist-box" style="display: none; top: 2.1rem;">
						<!--<li class="mui-ellipsis companyitem" v-for="i in companylist">{{i.name}}</li>-->

					</ul>
					<li class="mui-table-view-cell  mui-table-view-list mui-clearfix">
						<div class="mui-input-row border">
							<label>地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;址：</label>
							<input type="text" id="oaway" class="mui-input-clear" placeholder="请输入地址" :value="companydata.oaway||way" readonly>
						</div>
					</li>
					<li class="mui-table-view-cell  mui-table-view-list mui-clearfix">
						<div class="mui-input-row border">
							<label style="width:2rem!important;">法定代表人：</label>
							<input type="text" id="legalname" class="mui-input-clear" placeholder="请输入法定代表人" :value="companydata.legaluser||addlist.legaluser" readonly>
						</div>
					</li>
					<li class="mui-table-view-cell  mui-table-view-list mui-clearfix">
						<div class="mui-input-row border">
							<label>手机号码：</label>
							<input type="text" id="phone" class="mui-input-clear" placeholder="请输入手机号码" :value="companydata.phone||addlist.phone" readonly>
						</div>
					</li>
					<!--<li class="mui-table-view-cell  mui-table-view-list mui-clearfix">
                    <div class="mui-input-row border">
                        <label>许可证号:</label>
                        <input type="text" id="cenumber" class="mui-input-clear" placeholder="请输入许可证号" :value="companydata.cenumber||addlist.cenumber" readonly>
                    </div>
                </li>-->

				</ul>

				<ul class="mui-table-view">
					<li class="mui-table-view-cell mui-table-view-first ">
						<span>检查信息</span>
					</li>
					<li class="mui-table-view-cell  mui-table-view-list mui-clearfix" xbzx-verify="date">
						<div class="mui-input-row border">
							<label class="must">检查日期：</label>
							<input title="开始日期" type="text" class="mui-input-clear jcdata" id='demo3' readonly name="supervise.inspectdate" :value="list.inspectdate" data-options='{"labels":["年", "月", "日", "时段", "分"],"beginYear":2010,"endYear":2020}' @click="dataSelect01($event)" placeholder="请选择开始检查日期">
							<span style="margin-right:.5rem ;">-</span>
							<input title="结束日期" type="text" class="mui-input-clear jcdata" id='demo2' readonly name="supervise.enddate" :value="list.enddate" data-options='{"labels":["年", "月", "日", "时段", "分"],"beginYear":2010,"endYear":2020}' @click="dataSelect02($event)" placeholder="请选择结束检查日期">
						</div>
					</li>
					<li class="mui-table-view-cell  mui-table-view-list mui-clearfix" id="personli" xbzx-verify="person">
						<div class="mui-input-row border" id="person">
							<input type="hidden" id="cbksdids" name="supervise.cbksdids" value="" />
							<input type="hidden" id="zfddids" name="supervise.zfddids" value="" />
							<input type="hidden" id="cbrid" name="supervise.cbrid" value="" />
							<label class="psl must">检查人员：</label>
							<input id="persondatabox" type="hidden" class="mui-input-clear" placeholder="请选择检查人员" name="supervise.checkuser" value="">
							<div class="psbox">
								<div class="inb mui-checkbox mui-left" v-for="i in person">
									<label>{{i.uname}}</label>
									<input id="" class="personinput" type="checkbox" :value="i.uname">
								</div>
							</div>
						</div>
					</li>
					<li class="mui-table-view-cell  mui-table-view-list mui-clearfix" xbzx-verify="result">
						<div class="mui-input-row border" id="personbox">
							<label class="must">检查结果：</label>
							<div class="mui-radio mui-left mui-pull-left">
								<label>符合要求</label>
								<input type="radio" title="符合要求" @click="check($event)" name="supervise.result" value="符合要求">
							</div>
							<div class="mui-radio mui-left mui-pull-left">
								<label>限时整改</label>
								<input type="radio" title="限时整改" @click="check($event)" name="supervise.result" value="限时整改">
							</div>
							<div class="mui-radio mui-left mui-pull-left">
								<label>涉嫌违法</label>
								<input type="radio" title="涉嫌违法" @click="check($event)" name="supervise.result" value="涉嫌违法">
							</div>
						</div>
					</li>
					<li class="mui-table-view-cell  mui-table-view-list mui-clearfix upbook" xbzx-verify="img">
						<div class="mui-input-row border ">
							<label class="must" id="sss">检查记录表上传</label>
							<div id="imgupbox">
								<a href="javascript:;" @click="imgup()"></a>
								<div :id="'img'+index" class="imgList" v-for="(i,index) in imgsrc">
									<span class="close">X</span>
									<img :src="imgsrcfirst+i.path" data-preview-src='' data-preview-group='1' />
								</div>
								<input type="hidden" name="imgUrl" :id="index" :value="i.path" v-for="(i,index) in imgsrc" />
							</div>
						</div>

					</li>

				</ul>

				<ul class="mui-table-view" id="timelimitbox" style="display: none;">
					<li class="mui-table-view-cell mui-table-view-first ">
						<span>整改信息</span>
					</li>
					<li class="mui-table-view-cell  mui-table-view-list mui-clearfix" xbzx-verify="time">
						<div class="mui-input-row border" id="databox">
							<label class="must">整改时限：</label>
							<div class="mui-radio mui-left mui-pull-left">
								<label>3天</label>
								<input type="radio" class="radio" name="supervise.timelimit" value="3">
							</div>
							<div class="mui-radio mui-left mui-pull-left">
								<label>7天</label>
								<input type="radio" class="radio" name="supervise.timelimit" value="7">
							</div>
							<div class="mui-radio mui-left mui-pull-left">
								<label>15天</label>
								<input type="radio" class="radio" name="supervise.timelimit" value="15">
							</div>
							<div class="mui-radio mui-left mui-pull-left">
								<label>30天</label>
								<input type="radio" class="radio" name="supervise.timelimit" value="30">
							</div>
							<div class="mui-radio mui-left mui-pull-left" v-if="pd">
								<label>其他</label>
								<input id="otherdata" type="radio" class="radio" name="supervise.timelimit" value="其他">
							</div>
							<div class="mui-radio mui-left mui-pull-left" v-else>
								<label>其他</label>
								<input id="otherdata" type="radio" class="radio" name="supervise.timelimit" value="其他">
							</div>
							<input id="otherdate" class="mui-input-clear inputdata" style="width: 2rem;display: none;" type="text" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" maxlength="3" placeholder="请输入天数">
							<span class="inputdata" style="display: none;">
								天
							</span>
						</div>
					</li>
					<li class="mui-table-view-cell  mui-table-view-list mui-clearfix" xbzx-verify="reatrequest">
						<div class="mui-input-row border">
							<label>整改要求：</label>
							<input type="text" class="mui-input-clear" name="supervise.reatrequest" :value="list.reatrequest" placeholder="请输入整改要求（100字以内 ）" maxlength="100">
						</div>
					</li>

				</ul>

			</div>
		</form>
		<script src="js/mui.min.js"></script>
		<script src="js/lib/vue.js"></script>
		<script src="js/lib/jquery-1.11.0.js"></script>
		<script src="js/common/rutour.js"></script>
		<script src="js/common/server_commonFun.js"></script>
		<script src="js/lib/mui.picker.min.js"></script>
		<script src="js/lib/mui.poppicker.js"></script>
		<script src="js/lib/mui.zoom.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/lib/mui.previewimage.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			mui.init();
			mui.plusReady(function() {
				var currentView = plus.webview.currentWebview(); // 获取 当前webview
				currentView.show('slide-in-right', 300); // 显示当前webview (方式,时间)
				plus.nativeUI.closeWaiting(); // 关闭系统 loading 等待框
				//获得事件参数
				var current = plus.webview.currentWebview();
				vm.id = current.newsid;
				vm.ywid = current.ywid;
				console.log(vm.id);
				if(vm.id != null) {
					$(".mui-title").text("编辑"); //改标题
				}
			})
			var vm = new Vue({
				el: "#Edit",
				data: {
					id: '', //编辑传入id
					pd: false, //新增编辑标识
					list: {}, //编辑回显数据
					token: '', //登录token
					pickerlist: '', //下拉列表数据
					radios: 0,
					companylist: {}, //企业搜索返回列表
					companydata: {}, //企业信息
					person: '',
					persondata: [],
					persondata02: [],
					files: [],
					type: '1',
					imgsrc: {}, //图片路径
					imgsrcfirst: '',
					index: 0,
					ywid: '',
					addlist: {},
					flag: false,
					len: 0, // 图片数量
					company: {}, //单位信息
					address: {}, //地址
					imgIndex: 0, // 第几张
					imgfiles: [], // 已上传图片路径
					sub: true, //提交标识
					stutas: false, //单位是否选中
					upindex: 0, // 上传开始
					way: '' // 地址
				},
				mounted: function() {
					this.init();
				},
				methods: {
					init: function() {
						mui.plusReady(function() {
							vm.token = plus.storage.getItem('token');
							console.log(vm.token);

							mui.previewImage();
							//同科室人员数据
							mui.ajax(
								rutour.supervision.department + vm.token, {
									dataType: 'json', //服务器返回json格式数据
									async: false, //先加载人员数据
									type: 'get', //HTTP请求类型
									success: function(res) {
										vm.person = res.data;
										console.log(vm.person);
									},
									error: function(xhr, type, errorThrown) {
										//异常处理；
										console.log(type);
									}
								});
							//新增编辑判断
							if(vm.id != null) {
								vm.pd = true; //编辑为true
								vm.stutas = true; //单位是否选中
								mui.ajax(
									rutour.supervision.detail + vm.token, {
										data: {
											id: vm.id
										},
										dataType: 'json', //服务器返回json格式数据
										type: 'get', //HTTP请求类型
										success: function(res) {
											vm.list = res.data.object;
											vm.company = res.data.legaluser;
											vm.address = res.data.address;
											console.log(vm.list);
											vm.backdata(vm.list.result);
											//科室人员回显
											console.log(vm.list.checkuser)
											vm.persondata02 = vm.list.checkuser.split(',');
											console.log(vm.persondata02)
											$.each(vm.persondata02, function(index, value) {
												$(".psbox input[value='" + value + "']").prop("checked", true);
											})
											//图片回显
											vm.imgsrcfirst = res.data.osspath;
											vm.imgsrc = res.data.filelist;
											vm.index = vm.imgsrc.length; // 初始化图片个数
											vm.upindex = vm.imgsrc.length; // 初始化图片标记id
											console.log('图片' + vm.imgsrc);
											console.log(vm.imgsrcfirst);
											//整改时限回显其他判断
											if(vm.list.timelimit == '3' || vm.list.timelimit == '7' || vm.list.timelimit == '15' || vm.list.timelimit == '30') {
												$("#timelimitbox input[value='" + vm.list.timelimit + "']").prop("checked", true);
												$(".inputdata").hide()
												$(".inputdata").val("")
											} else {
												$(".inputdata").val(vm.list.timelimit)
												$("#otherdata").attr("checked", true);
												$(".inputdata").show()
											}

											//检查结果
											if(vm.list.result == "限时整改") {
												$("#timelimitbox").show()
											}
											//被查单位回显
											$("#companyinput").val(res.data.legaluser.name);
											vm.companydata.oaway = res.data.address.city + res.data.legaluser.oaway + res.data.legaluser.address;
											vm.companydata.phone = res.data.legaluser.phone;
											vm.companydata.cenumber = res.data.legaluser.cenumber;
											vm.companydata.legaluser = res.data.legaluser.legalname;
										},
										error: function(xhr, type, errorThrown) {
											console.log(type);
										}
									});
							} else if(vm.ywid != null) { // 扫一扫新增
								vm.flag = true;
								vm.stutas = true; //单位是否选中
								mui.ajax(rutour.supervision.getEnterpriseByYwid + vm.token, {
									data: {
										ywid: vm.ywid
									},
									dataType: 'json', //服务器返回json格式数据
									type: 'get', //HTTP请求类型
									success: function(res) {
										vm.addlist = res.data;
										console.log(vm.addlist);
										vm.way = vm.ifElse(vm.addlist.city) + '' + vm.ifElse(vm.addlist.oaway) + '' + vm.ifElse(vm.addlist.address);
									},
									error: function(xhr, type, errorThrown) {
										console.log(type);
									}
								});
							};

						});
					},
					ifElse: function(value) {
						value = (value != null) ? value : '';
						return value
					},
					backdata: function(checksel) {
						//回显骚操作
						$("input[value='" + checksel + "']").prop("checked", true);

					},
					check: function() { //检查结果点击判断
						if($(event.currentTarget).val() == "限时整改") {
							$("#timelimitbox").show()
						} else {
							$("#timelimitbox").hide()
						}
					},
					companysearch: function() {
						vm.stutas = false;
						var name = $("#companyinput").val();
						var companyname = $('.companyitem').text()

						console.log(name)
						mui.ajax(
							rutour.supervision.EnterpriseList + vm.token, {
								data: {
									name: name
								},
								dataType: 'json', //服务器返回json格式数据
								type: 'get', //HTTP请求类型
								success: function(res) {
									$("#companylist-box").empty(); //清空盛装容器
									vm.companylist = res.data;
									for(var i = 0; i < vm.companylist.length; i++) {
										$("#companylist-box").append('<li class="mui-ellipsis companyitem" >' + vm.companylist[i].name + '</li>')
									}
									console.log(vm.companylist);
									$("#cenumber").val('');
									$("#oaway").val('');
									$("#legalname").val('');
									$("#phone").val('');
									$("#hiddenywid").val('')
									$("#xzqh").val('')
									mui("#companylist-box").on("tap", ".companyitem", function() {
										vm.stutas = true;
										$("#companyinput").val($(this).text());
										$("#companylist-box").hide(); //换成失去焦点更好
										for(var i = 0; i < vm.companylist.length; i++) {
											console.log(vm.companylist[i].name)
											if(vm.companylist[i].name == $("#companyinput").val()) {
												$("#cenumber").val(vm.companylist[i].cenumber);
												$("#oaway").val(vm.companylist[i].city + vm.companylist[i].oaway + vm.companylist[i].address);
												$("#legalname").val(vm.companylist[i].legalname);
												$("#phone").val(vm.companylist[i].phone);
												$("#hiddenywid").val(vm.companylist[i].ywid)
												$("#xzqh").val(vm.companylist[i].city)
											}
										}
										console.log(vm.companylist)
										vm.companylist = '';
									})

								},
								error: function(xhr, type, errorThrown) {
									console.log(type);
								}
							});
					},
					editaddsub: function() {
						//表单验证
						$(".mui-table-view-list").each(function() {
							var type = $(this).attr('xbzx-verify');
							switch(type) {
								case "name":
									_this = $(this).find('input')[0];
									if($(_this).val() == '') {
										mui.toast($(_this).attr('placeholder'));
										$(_this).focus();
										vm.sub = false;
										return false;
									} else if(!vm.stutas) {
										mui.toast("请重新输入被查单位");
										vm.sub = false;
										return false;
									} else {
										vm.sub = true;
									}
									break;
								case "date":
									_this1 = $(this).find('input')[0];
									_this2 = $(this).find('input')[1];
									if($(_this1).val() == '') {
										mui.toast($(_this1).attr('placeholder'));
										$(_this1).focus();
										vm.sub = false;
										return false;
									} else if($(_this2).val() == '') {
										mui.toast($(_this2).attr('placeholder'));
										$(_this2).focus();
										vm.sub = false;
										return false;
									} else {
										vm.sub = true;
									}
									break;
								case "person":
									_this = $('#persondatabox')
									if($(".psbox input[type=checkbox]:checked").length == 0) {
										mui.toast(_this.attr('placeholder'));
										vm.sub = false;
										return false;
									} else {
										vm.sub = true;
									}
									break;
								case "result":
									if($("#personbox input[type=radio]:checked").length == 0) {
										mui.toast("请选择检查结果");
										vm.sub = false;
										return false;
									} else {
										vm.sub = true;
									}
									break;
								case "img":
									if($(".imgList").length == 0) {
										mui.toast("请上传检查记录表");
										vm.sub = false;
										return false;
									} else {
										vm.sub = true;
									}
									break;
								case "time":
									if($("#personbox input[value='限时整改']:checked").length == 1) {
										if($("#databox input[type=radio]:checked").length == 0) {
											mui.toast("请选择整改期限");
											vm.sub = false;
											return false;
										} else if($("#databox input[value='其他']:checked").length == 1 && $("#otherdate").val() == '') {
											mui.toast($("#otherdate").attr('placeholder'));
											vm.sub = false;
											return false;
										} else {
											vm.sub = true;
										}
									}
									break;

								default:
									break;
							}

						})
						//表单提交
						if(vm.sub) {
							vm.persondata = [];
							$(".mui-checkbox input[type=checkbox]").each(function() {
								if($(this).prop("checked")) {
									vm.persondata.push($(this).val())
								}
							})
							//其他天数塞值
							$('#otherdata').val($('.inputdata').val())
							$("#persondatabox").val(vm.persondata)
							console.log(vm.persondata)
							//权限管理数据
							var dids;
							var dywid = []; //放发送02的数组
							var ywid = []; //放发送03的数组
							for(var i = 0; i < vm.person.length; i++) { //所有数据项循环
								for(var j = 0; j < vm.persondata.length; j++) { //已经选择人员循环
									if(vm.persondata[j] == vm.person[i].uname) { //选择人员和数据中对比相同
										dids = vm.person[1].dids;
										ywid.push(vm.person[i].ywid) //03
										if(vm.person[i].dywid != null) {
											dywid.push(vm.person[i].dywid) //拿出02
										} else {
											if(vm.person[i].userywid != null) {
												dywid.push(vm.person[i].userywid) //03
											}
										}
									}
								}
							}
							$.unique(dywid.sort()); //jq数组去重
							$("#cbksdids").val(dids);
							$("#zfddids").val(dywid);
							$("#cbrid").val(ywid)

							mui.ajax(
								rutour.supervision.save + vm.token, {
									data: $('#Edit').serialize(),
									dataType: 'json', //服务器返回json格式数据
									type: 'post', //HTTP请求类型
									success: function(res) {
										console.log(res);
										mui.toast(res.msg);
										var current = plus.webview.currentWebview();
										var pen = plus.webview.getWebviewById('scanSupervision.html');
										var par = current.opener();
										var pars = par.opener();
										if(vm.id != null) { // 编辑
											mui.fire(par, 'refresh', {
												flag: true
											});
											mui.fire(pars, 'refresh');
											mui.fire(pen, 'refresh', { // 扫一扫详情编辑
												flag: true
											});
										} else if(vm.ywid != null) { // 扫一扫新增
											console.log(pen)
											mui.fire(pen, 'refresh', {
												flag: true
											});
										} else {
											mui.fire(par, 'refresh');
										}
										plus.webview.close(current);
									},
									error: function(xhr, type, errorThrown) {
										//异常处理；
										console.log(type);
									}
								});
						} else {
							return false;
						}

					},
					//日期选择
					dataSelect01: function(event) {
						event.preventDefault()
						console.log($(event.currentTarget));
						var tager = $(event.currentTarget);
						var optionsJson = tager.attr('data-options') || '{}';
						var options = JSON.parse(optionsJson);
						var picker = new mui.DtPicker(options);
						picker.show(function(rs) {
							tager.val(rs.text)
							console.log(rs.value)
							picker.dispose();
						});
					},
					dataSelect02: function(event) {
						var begin;
						var end;
						event.preventDefault()
						console.log($(event.currentTarget));
						var tager = $(event.currentTarget);
						var optionsJson = tager.attr('data-options') || '{}';
						var options = JSON.parse(optionsJson);
						var picker = new mui.DtPicker(options);
						picker.show(function(rs) {
							tager.val(rs.text);
							begin = $('#demo3').val();
							end = $('#demo2').val();
							console.log($('#demo3').val());
							console.log($('#demo3').val());
							if(begin > end) {
								mui.toast("开始时间必须小于结束时间")
								$('#demo3').val('');
								$('#demo2').val('');
							}
							console.log(rs.value);
							picker.dispose();
						});
					},
					picker: function(ele, type) {
						//获取转换下拉列表
						vm.arr = []; //多次点击清空不会重复
						console.log(vm.pickerlist);
						for(var i = 0; i < type.length; i++) {
							vm.arr.push(type[i].dmmc);
						}
						var userPicker = new mui.PopPicker();
						userPicker.setData(vm.arr);
						userPicker.show(function(items) {
							ele.val(items[0]);
						});
					},
					upload: function(index) {
						// 图片文件
						var $num = $('.imgList').length;
						var wt = plus.nativeUI.showWaiting('正在上传第' + ($num + 1) + '张图片');
						var task = plus.uploader.createUpload(rutour.upload, {
								method: "POST",
							},
							function(t, status) { //上传完成
								if(status == 200) {
									plus.storage.setItem("uploader", t.responseText);
									console.log(t.responseText);
									console.log(t);

									var $div = '<div id="img' + vm.upindex + '" class="imgList"></div>';
									$('#imgupbox').append($div);
									var $close = '<span class="close">X</span>';
									$("#img" + vm.upindex).append($close);
									$("#img" + vm.upindex).append("<img src='" + vm.files[index].path + "' data-preview-src='' data-preview-group='1'>");

									$('#imgupbox').append('<input type="hidden" name="imgUrl" id="' + vm.upindex + '" value="' + JSON.parse(t.responseText).url + '"  />');
									vm.upindex++;
									index++; // 获取添加文件的下标
									if(index >= vm.files.length) {
										wt.close();
										mui.toast("上传完成");
									} else {
										wt.close();
										vm.upload(index);
									};
									vm.delImg();
								} else {
									console.log(status);
									mui.toast("上传失败");
									index++;
									if(index >= vm.files.length) {
										wt.close();
									} else {
										vm.upload(index);
									}
								}
							},
							function(e) {
								mui.toast("已取消上传");
								vm.len--;
							}
						);
						task.addData("client", "HelloH5+");
						task.addData("uid", getUid());
						console.log(vm.files[0])
						task.addFile(vm.files[index].path, {
							key: vm.files[index].name
						});

						task.start();
						//产生一个随机数
						function getUid() {
							return Math.floor(Math.random() * 100000000 + 10000000).toString();
						}
					},
					imgup: function() {
						if(vm.len >= 5) {
							plus.nativeUI.toast('最多只能上传5张图片');
							return false;
						}
						mui.plusReady(function() {
							$("#imgupbox img").each(function(index) {
								index + 1
								console.log(index)
							})
							vm.files = [];
							if(mui.os.plus) {
								var a = [{
									title: "拍照"
								}, {
									title: "从相册选择"
								}];
								plus.nativeUI.actionSheet({
									cancel: "取消",
									buttons: a
								}, function(b) { /*actionSheet 按钮点击事件*/
									switch(b.index) {
										case 1:
											appendByCamera(); /*拍照*/
											break;
										case 2:
											galleryImg(); /*相册*/
											break;
										default:
											break;
									}
								})
							}
							// 拍照添加文件
							function appendByCamera() {
								plus.camera.getCamera().captureImage(function(p) {
									appendFile(p);
								});
							}
							// 从相册中添加文件
							function galleryImg() {
								var $limit = 5 - $('.imgList').length; // 设置最多选择几张图片
								plus.gallery.pick(function(path) {
									var len = path.files.length
									for(var i = 0; i < len; i++) {
										var _i = i;
										for(var j = 0; j < vm.imgfiles.length; j++) {
											var _j = j;
											if(path.files[_i] == vm.imgfiles[_j]) {
												path.files.splice(_i, 1);
											}
										}
									}
									vm.imgfiles = vm.imgfiles.concat(path.files);
									if(path.files.length != len && path.files.length != 0) {
										plus.nativeUI.toast('已自动去除重复图片');
										appendFile(path);
									} else if(path.files.length == 0) {
										plus.nativeUI.toast('上传图片重复,请重新选择图片上传');
									} else {
										appendFile(path);
									}
								}, function(e) {
									console.log('取消选择图片');
								}, {
									filter: 'image',
									multiple: true,
									system: false,
									maximum: $limit
								});
							}
							//声明对象
							function setObj(name, path) {
								this.name = name;
								this.path = path;
							}
							// 添加文件
							function appendFile(p) {
								console.log(p);
								if(p.files) {
									for(var i = 0, len = p.files.length; i < len; i++) {
										var _i = i;
										//就是这里
										var arrItem = new setObj('uploadKey' + vm.index, p.files[_i])
										vm.files.push(arrItem);
										vm.index++; // 图片id 初始化的值
									};
									vm.upload(vm.imgIndex);
								} else {
									plus.io.resolveLocalFileSystemURL(p, function(entry) {
										var path = entry.toLocalURL();
										var arrItem = new setObj('uploadKey' + vm.index, path);
										vm.files.push(arrItem);
										vm.index++; // 图片id 初始化的值
										vm.upload(vm.imgIndex);
									});
								}
							};

						});

					},
					delImg: function() { //上传图片删除
						vm.len = $('.close').length;
						$('.close').unbind('tap')
						$('.close').on('tap', function() {
							var $id = $(this).parent().attr('id');
							var path = $(this).siblings().attr('src');
							for(var i = 0; i < vm.files.length; i++) {
								var _i = i;
								if(vm.files[_i].path == path) {
									vm.files.splice(_i, 1);
								}
							}
							for(var i = 0; i < vm.imgfiles.length; i++) {
								var _i = i;
								if(vm.imgfiles[_i] == path) {
									vm.imgfiles.splice(_i, 1);
								}
							}
							$zid = $id.substring($id.indexOf('g') + 1, $id.length); // input id
							$("#" + $zid).remove();
							$("#" + $id).remove();
							vm.len--;
						})
					}
				},
				updated: function() {
					this.$nextTick(function() {
						//vue更新事件操作
						$("#databox .mui-radio").on("tap", function() {
							if($(this).children(".radio").val() == "其他") {
								$(".inputdata").show()
							} else {
								$(".inputdata").hide()
							}
						});

						mui("#companyinput-box").on("tap", "#companyinput", function() {
							$("#companylist-box").show();
						})

						vm.delImg();

						mui.previewImage();
					})
				}
			})
		</script>
	</body>

</html>